import gradio as gr

from autogpt import agent
from translate_chain import translate_chain, parse_translation


def autogpt_chat(message, history):
    resp = agent.run([message])
    # prompt = translate_prompt_template.format(src=message, result=resp)
    translated_str = translate_chain.run(src=message, result=resp)
    return parse_translation(translated_str)


def launch_gradio():
    demo = gr.ChatInterface(
        fn=autogpt_chat,
        title="autogpt",
        # retry_btn=None,
        # undo_btn=None,
        chatbot=gr.Chatbot(height=600),
    )

    demo.launch(share=True, server_name="0.0.0.0")


if __name__ == '__main__':
    launch_gradio()
    # print(agent.run(["2023年成都大运会，中国金牌数是多少"]))
